package com.finley.flowabledemo.controller;


import com.github.xingshuangs.iot.protocol.modbus.service.ModbusTcp;
import com.github.xingshuangs.iot.protocol.modbus.service.ModbusTcpServer;
import com.github.xingshuangs.iot.utils.HexUtil;

/**
 * @description:
 * @author: xianfei.chao
 * @date 2025/7/3 13:41
 * @version: 1.0
 */
public class PlcServerDemo {

    public static void main(String[] args) {
        ModbusTcpServer server = new ModbusTcpServer();
        server.start();

        ModbusTcp modbusTcp = new ModbusTcp("127.0.0.1");
        // optional
        modbusTcp.setComCallback((tag, bytes) -> System.out.printf("%s[%d] %s%n", tag, bytes.length, HexUtil.toHexString(bytes)));

        modbusTcp.writeInt16(2, (short) 10);
        short data = modbusTcp.readInt16(2);
        System.out.println("data: " + data);
        modbusTcp.close();
        server.stop();
    }
}
